#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright @ 2014 OPS, Qunar Inc. (qunar.com)
#
# Author: tingfang.bao <tingfang.bao@qunar.com>
# DateTime: 15-3-10 下午6:19
from decorators import login_required, cached, templated
from flask import Flask, session
from werkzeug.routing import Rule

app = Flask(__name__)
app.secret_key = "123"


@app.route("/")
@login_required
def index():
    return 'index'


@app.route('/calc')
@cached(timeout=5)
def calc():
    return 'all ok'


@app.route('/login')
def login():
    session['user'] = "baotingfang"
    return 'login OK'


@app.route('/logout')
def logout():
    session.clear()
    return 'bye'


@app.route('/template')
@templated()
def templated():
    return {
        "name": "baotingfang",
        "age": 30
    }

# 自己做映射
app.url_map.add(Rule("/my", endpoint="abc"))


@app.endpoint('abc')
def method1():
    return 'haha abc'


if __name__ == '__main__':
    app.run(debug=True)

